<?php
goto next;
/*
$day["lunes"]["from"]["hour"] = "01";
$day["lunes"]["from"]["min"]  = "59";
$day["lunes"]["from"]["part"] = "am";
$day["lunes"]["to"]["hour"] = "01";
$day["lunes"]["to"]["min"]  = "59";
$day["lunes"]["to"]["part"] = "am";

$day["martes"]["from"]["hour"] = "01";
$day["martes"]["from"]["min"]  = "59";
$day["martes"]["from"]["part"] = "am";
$day["martes"]["to"]["hour"] = "01";
$day["martes"]["to"]["min"]  = "59";
$day["martes"]["to"]["part"] = "am";



die(var_dump($day)); */

function array_clean(array $haystack)
{
	foreach ($haystack as $key => $value) {
		if (is_array($value)) {
			$haystack[$key] = array_clean($value);
		} elseif (is_string($value)) {
			$value = trim($value);
		}

		if (!$value) {
			unset($haystack[$key]);
		}
	}

	return $haystack;
}

if ($_POST["submit"]) {
	/*$array = array_filter($_POST["day"], function($a){
		return array_filter($a["from"]) || array_filter($a["to"]);
	});*/
	//var_dump($array);
	
	/*$array = array_filter($_POST["day"], function($a){
		return trim($a["from"]) !== "" && trim($a["to"]) !== "";
	});
	
	die(var_dump($array));*/
	
	//die(var_dump($_POST["day"]));
	
	
	if (sizeof($_POST["day"]) > 0) {
		foreach ($_POST["day"] as $k => $v) {
			foreach ($v as $d => $h) {
				echo "INSERT INTO 'horario' (restaurantId, tipohorarioId, dia, horaDesde, horaHasta) VALUES ('xx', '$k', '$d', '{$h["from"]}', '{$h["to"]}')". PHP_EOL;
				//$this ->query("INSERT INTO {$this ->gTable('horario')} (restaurantId, tipohorarioId, dia, horaDesde, horaHasta) VALUES ('{$this ->id}', '$k', '$d', '', '')");
			}
		}
	}
}


?>
<form method="post" >
<!-- input type="checkbox" name="type[]" value="0"   /><input type="checkbox" name="type[]" value="1"   /-->
	<input type="text" name="day[1][lunes][from]" value="a" />:
	<input type="text" name="day[1][lunes][to]" value="b" />
	<input type="text" name="day[1][martes][from]" value="c" />:
	<input type="text" name="day[1][martes][to]" value="d" />
	<input type="text" name="day[2][lunes][from]" value="c" />:
	<input type="text" name="day[2][lunes][to]" value="d" />
	<input type="submit" name="submit" value="enviar" />

</form>


<?php
exit();
next:

$pPageIsPublic = false;
include '../_common.php';


$_SESSION ["m1"] = "restaurant";
$_SESSION ["m2"] = "restaurant-list";
$objName = "Restaurant";
$objUrl = "restaurant";
$objTitle = "Restaurant";

$pTitle = "Nuevo {$objTitle}";
$pButton = 'Guardar';
$action = 'add';
$id = intval ( $_REQUEST ['id'] );
$seo = NULL;

$objLoad = new Restaurant();
$objLoad->setUid ( $id );
if ($objLoad->load ()) {
	$pTitle = "Editar {$objTitle}";
	$pButton = 'Actualizar';
	$action = 'edit';
	$seo = json_decode($objLoad ->seo);
}

if (isset ( $_POST ['submit'] )) {
	$objLoad->setAuto ( $_POST );
	$objLoad ->seo = arr2json($_POST, array('metaTitle', 'metaDescription', 'metaKeyword', 'friendlyUrl'));
	$objLoad ->_horario = $_POST["day"];
	$objLoad ->_tipococina = $_POST["tipococinaId"];
	$objLoad ->_mediopago = $_POST["mediopagoId"];
	
	if ($_POST ['action'] == 'edit') {
		$objLoad->getConnection ();
		$objLoad->setUid ( $id );
		$objLoad ->update ();
		Tzn::redirect ( "{$objUrl}-list.php", "{$objTitle} ha sido actualizado." );
	} elseif ($_POST ['action'] == 'add') {
		$objLoad->add ();
		Tzn::redirect ( "{$objUrl}-add.php?id={$objLoad ->id}", "{$objTitle} ha sido registrado." );
	}
}
?>
<?php include ("header.php"); ?>
<?php

//$tabs = array ('zona' => 1, 'zonamaps' => 2, 'menu' => 3, 'file' => 4);
$tabs = array ('menu' => 1, 'file' => 2);
$selTab = $tabs [$_REQUEST ['tab']] ? $tabs [$_REQUEST ['tab']] : 0;
?>
<script type="text/javascript">
$(document).ready(function(){
	$("#frmMain").validate();
	$x = $('#content-tabs').tabs({
		disabled :[<?php echo !$objLoad ->isLoaded() ? "1,2,3,4" : "" ?>],
		active   : <?php echo $selTab?>
	});
	
	$('#tipococinaId').multiSelect({ selectAll: false, oneOrMoreSelected: '*', noneSelected : 'Seleccionar tipos de cocinas' });
	$('#mediopagoId').multiSelect({ selectAll: false, oneOrMoreSelected: '*', noneSelected : 'Seleccionar medios de pagos ' });

	$('.hour').timepicker({
		hourGrid: 4,
		minuteGrid: 10,
		timeFormat: 'hh:mm tt'
	});
});
</script>
<?php include("sidebar.php"); ?>
<ul id="subnav">
	<li><a class="back" href="<?= $objUrl ?>-list.php"> Atras </a></li>
	<li class="noborder"><a class="add" href="<?= $objUrl ?>-add.php"> Agregar <?= $objTitle ?> </a>
	</li>
</ul>
<div id="list">
	<h2> <?php echo $pTitle;?> </h2>
	<div id="content-tabs">
		<ul>
			<li><a href="#fragment-1"><span>Restaurant</span></a></li>
			<!-- li><a href="#fragment-2"><span>Zonas de Cobertura</span></a></li-->
			<!-- li><a href="#fragment-3"><span>Localizaci&oacute;n (Google Maps)</span></a></li-->
			<li><a href="#fragment-2"><span>Men&uacute;s</span></a></li>
			<li><a href="#fragment-3"><span>Galer&iacute;a de Im&aacute;genes</span></a></li>
		</ul>
		<div id="fragment-1">
			<form action="" method="post" name="frmMain" id="frmMain">
				<fieldset>
					<legend> Informaci&oacute;n General </legend>
					<table cellpadding="0" cellspacing="0" class="table-form">
						<tr>
							<th width="16%" >T&iacute;tulo:</th>
							<td><?php $objLoad ->qText('titulo', '', 'width:520px', 'class="required"');?></td>
						</tr>
						<tr>
							<th>Descripcion:</th>
							<td><?php $objLoad ->qTextArea('descripcion', '', 'width:520px; height:70px;', '');  //qEditor('description', array('toolbar' => 'custom') ); ?></td>
						</tr>
						<tr>
							<th>Tipos de Cocinas:</th>
							<td><?php $objLoad ->pSelectCheckBoxTipoCocina();  ?></td>
						</tr>
						<?php $objLoad ->printSEO();  ?>
						<tr>
							<th>Estado:</th>
							<td><?php $objLoad ->arrayToSelect($objLoad ->_arrStatus, 'estado', $objLoad ->estado, false, 'width:100px', '');?></td>
						</tr>
						
					</table>
				</fieldset>
				<fieldset>
					<legend> Informaci&oacute;n de Pedidos Delivery </legend>
					<table cellpadding="0" cellspacing="0" class="table-form">
						<tr>
							<th width="25.6%" >Formas de Pago:</th>
							<td><?php $objLoad ->pSelectCheckBoxMedioPago();  ?></td>
						</tr>
						<tr>
							<th>Orden M&iacute;nima:</th>
							<td><?php $objLoad ->qText('orderMin', '', 'width:60px', 'class=""');?></td>
						</tr>
						<tr>
							<th>Costo Entrega:</th>
							<td><?php $objLoad ->qText('costoEntrega', '', 'width:60px', 'class=""');?></td>
						</tr>
						<tr>
							<th>Tiempo Entrega:</th>
							<td><?php $objLoad ->qText('tiempoEntrega', '', 'width:60px', 'class=""');?></td>
						</tr>
					</table>
				</fieldset>
				<fieldset>
					<legend> Horarios </legend>
					<?php $objLoad ->pHorary(); ?>
				</fieldset>
				<div style="margin-top: 10px">
					<input type="hidden" name="id" value="<?php echo $id; ?>" /> <input
						type="hidden" name="action" value="<?php echo $action; ?>" /> <input
						type="submit" name="submit" value="<?php echo $pButton; ?>" />
					&nbsp; <input type="reset" value="Cancelar"
						onClick="window.location.href='<?= $objUrl ?>-list.php'" />
				</div>
			</form>
		</div>
		<div id="fragment-2"></div>
		<div id="fragment-3"></div>
		<!-- div id="fragment-4"></div>
		<div id="fragment-5">
			<?php
			/*$objPage = clone $objLoad;
			global $returnUrl, $sideMenu;
			$returnUrl = "project"; // general: page
			$sideMenu = "project"; // general: page
			include PRJ_INCLUDE_PATH . 'admin/page-image-list.php';*/
			?>
		</div-->
	</div>
</div>
<?php include("footer.php"); ?>